package com.woniuxy.Job;

import com.woniuxy.service.log.LogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class ClearDataJob {
    private static final Logger logger = LoggerFactory.getLogger(ClearDataJob.class);
    @Autowired
    private LogService logService;

    @Scheduled(cron = "0 15 10 L * ?")
    public void clearDataJob(){
        logger.info("---------定时任务开始执行---------"+new SimpleDateFormat("HH:mm:ss").format(new Date()));
        clearData(logService);
        logger.info("---------定时任务执行成功---------"+new  SimpleDateFormat("HH:mm:ss").format(new Date()));
    }


    private static void clearData(LogService logService) {
        try{
            logService.deleteLogData();//调用service层的方法 删除数据库数据
        }catch (Exception e){
            logger.error("清理数据失败，失败原因："+e.getMessage());
        }
    }
}
